﻿<MudTextField T="string"
              @bind-Value="@Value"
              Immediate="@true"
              DebounceInterval="@DebounceInterval"
              Required="@true"
              RequiredError="Enter a star" />

<MudButton id="re-render-button"
           Variant="@Variant.Filled"
           Color="@Color.Primary"
           OnClick="@LaunchDelayedRerender">
    Launch delayed re-render
</MudButton>

<MudText>
    RenderCount: @_renderCount
</MudText>

<MudText>
    Value: @Value
</MudText>

@code {
    public static string __description__ = "Test user input retention on component refresh before debounce.";

    [Parameter]
    public string? Value { get; set; }

    public int DebounceInterval => 500;

    public int RerenderDelay => 2000;

    private int _renderCount;

    protected override void OnAfterRender(bool firstRender)
    {
        _renderCount++;

        base.OnAfterRender(firstRender);
    }

    private async Task LaunchDelayedRerender()
    {
        await Task.Delay(RerenderDelay);
        StateHasChanged();
    }
}